import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Service } from 'src/module/admin/service/entities/service.entity';
import { Repository } from 'typeorm';

@Injectable()
export class RecommendsService {
  constructor(
    @InjectRepository(Service)
    private readonly serviceRepository: Repository<Service>,
  ) {}
  async recommendService(): Promise<Service[] | any> {
    const res = await this.serviceRepository
      .createQueryBuilder('service')
      .leftJoinAndSelect('service.photos', 'photo')
      .take(4)
      .getMany();

    const resultPhoto = res
      .map((photos) => {
        return photos.photos;
      })
      .flat(1);

    return {
      recommendsPhotos: resultPhoto,
      recommendsServices: res,
    };
  }
}
